package com.tsystems.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import com.tsystems.entities.Employee;



public class EmployeeDAO extends AbstractDAO<Employee> {

	public Employee getEmployee(String login) {
		EntityManager em = TrainsEntityManager.getInstance();	
		CriteriaBuilder builder = em.getCriteriaBuilder();
		CriteriaQuery<Employee> criteria = builder.createQuery(Employee.class);
		
		Root<Employee> employee = criteria.from(Employee.class);
		criteria.select(employee);
		criteria.where(builder.equal(employee.get("login"), login));
		List<Employee> result = em.createQuery(criteria).getResultList();
		
		return !result.isEmpty() ? result.get(0) : null;
	}
	
	/*public void addEmployee(Employee employee) {
		EntityManager em = TrainsEntityManager.getInstance();	
		em.getTransaction().begin();
		em.persist(employee);
		em.getTransaction().commit();
	}*/
}
